package com.flyxiaozhu.erp.admin.controllers;

import com.flyxiaozhu.erp.core.entities.Permission;
import com.flyxiaozhu.erp.core.libs.JSONResult;
import com.flyxiaozhu.erp.core.libs.SearchSpecification;
import com.flyxiaozhu.erp.core.repositories.PermissionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class PermissionController {
    @Autowired
    PermissionRepository permissionRepository;

    @RequestMapping("/permission/select")
    public JSONResult select(HttpServletRequest request, @PageableDefault Pageable pageable) {
        Page<Permission> page = permissionRepository.findAll(new SearchSpecification<>(request), pageable);
        return new JSONResult(page, pageable.getPageNumber());
    }

    @RequestMapping("/permission/all")
    public JSONResult all(HttpServletRequest request) {
        List<Permission> list = permissionRepository.findAll(new SearchSpecification<>(request));
        return new JSONResult().put("list", list);
    }

    @RequestMapping("/permission/update")
    public JSONResult update() {
        return new JSONResult().put("gg", "f");
    }
}
